# -*- coding: utf-8 -*-
"""
Created on Thu Jun 14 10:18:10 2018

@author: Luther
"""
import os

path = input("input url list file:")
path_o = input("input output path:")
with open(path, encoding="utf-8") as f:
    text = f.read()
l = text.split("\n")[1:]

print("Read {} records successfully!".format(len(l)))
num = len(l) // 1000 + 1

html_head = '<!DOCTYPE html>\n<html>\n<head>\n<meta charset="utf-8">\n<title>MyHTML</title>\n</head>\n<body>\n'
html_tail = "</body>\n</html>"
for i in range(num):
    with open(
            os.path.join(path_o, "myHTML_{}.html".format(i)),
            'w',
            encoding="utf-8") as f:
        f.write(html_head)
        for j in l[i * 1000:i * 1000 + 1000]:
            f.write('<p><a href="{}">{}</a></p>'.format(j.split(",")[-1], j.split("/")[-1]))
        f.write(html_tail)
print('Completed!')
x = input()
